<template>
    <div>
        <!-- <div class="tabs">
            <div class="item" :class="{active: dynamicType == '00'}" @click="changeTabs('00')">文章</div>
            <div class="item" :class="{active: dynamicType == '01'}" @click="changeTabs('01')">视频</div>
        </div> -->
        <div class="search">
            <div class="input flex-v-center">
                <i class="icon-search mar-r10 color-999"></i>
                <input type="text" placeholder="搜索" placeholder-class="placeholder" v-model="keyword" @input="search">
                <div class="close">
                    <i v-if="keyword" class="icon-close color-999 fs26" @click="clearKeyword()"></i>
                </div>
            </div>
        </div>
        <div class="list">
            <articleItem 
                v-for="(item, index) in list" 
                @click="$navigate.to(`/pages/material/${item.dynamicType == '00' ? 'detail' : 'video' }?from=myMaterial&id=` + item.id, item.dynamicType == '00' ? true : false)"
                @refresh="onRefresh"
                :key="index" :item="item" type="myMaterial"></articleItem>
        </div>

        <pub-list-end :loading="scroll.loading" :max="scroll.max" :noData="scroll.noData"></pub-list-end>
        <div class="wfull h200"></div>

        <div class="float_btn">
            <div class="btn" @click="$navigate.to('/pages/create/index')">去创建内容</div>
            <div class="btn" @click="$navigate.to('/pages/user/myShare')">我的分享</div>
        </div>

    </div>
</template>

<script>
import articleItem from '@/components/pages/article-item.vue'
import { getDynamicList } from '@/request/art'
import { debounce } from '@/utils/functions'
export default {
    components: {
        articleItem
    },
    data() {
        return {
            keyword: '',
            dynamicType: '00', //00文章 01视频
            list: [],
            scroll: {
                page: 1,
                size: 30,
                loading: false,
                max: true,
                noData: false,
            },
        }
    },
    onLoad() {
        },
    onShow() {
        this.onRefresh()
    },
    onReachBottom() {
        this.onInfinite()
    },
    methods: {
        clearKeyword() {
            this.keyword = '';
            this.onRefresh()
        },
        search: debounce(function() {
            this.onRefresh()
        }),
        getList(complete) {
            getDynamicList({
                pageIndex: this.scroll.page,
                pageSize: this.scroll.size,
                // dynamicType: this.dynamicType,
                keyWord: this.keyword,
                isMy: '01'
            }, { complete }).then(res => {
                this.list = this.scroll.page == 1 ? res.data.list : this.list.concat(res.data.list)
                this.scroll.max = this.list.length >= res.data.total
                this.scroll.noData = res.data.total == 0
            })
        },
        changeTabs(type) {
            this.dynamicType = type
            this.onRefresh()
        },
        // 重头第一页刷新列表
        onRefresh() {
            this.scroll.loading = true
            this.scroll.max = false
            this.scroll.noData = false
            this.scroll.page = 1
            this.list = []
            this.getList(() => {
                this.scroll.loading = false;
                uni.stopPullDownRefresh()
            })
        },
        // 滚动到底部加载
        onInfinite() {
            if(this.scroll.loading || this.scroll.max) return
            this.scroll.loading = true
            this.scroll.page += 1
            this.getList(() => {
                this.scroll.loading = false
            })
        },
    }

}
</script>

<style lang="less" scoped>
.tabs {
    position: sticky;
    top: 0;
    z-index: 1;
    height: 90rpx;
    width: 100%;
    display: flex;
    background: #fff;
    border-bottom: 1px solid #ddd;
    .item{
        flex: 1;
        height: 100%;
        text-align: center;
        color: #666;
        line-height: 90rpx;
        &.active{
            font-weight: bold;
            position: relative;
            color: #333;
            &::after{
                content: "";
                position: absolute;
                bottom: 0;
                left: 50%;
                transform: translateX(-50%);
                width: 60rpx;
                height: 6rpx;
                background: @mainColor;

            }
        }

    }

}

.search{
    background: #fff;
    padding: 30rpx;
    .input{
        width: 100%;
        height: 80rpx;
        background: #f3f4f6;
        border-radius: 40rpx;
        padding: 0 10rpx 0 30rpx;
        input{
            flex: 1;
        }
        .close{
            width: 80rpx;
            height: 80rpx;
            .icon-close{
                width: 80rpx;
                height: 80rpx;
            }
        }
    }
}

.list{
    padding: 0 30rpx;
    background: #fff;
}

.float_btn{
    width: 100%;
    height: 120rpx;
    position: fixed;
    bottom: 20rpx;
    padding: 0 20rpx;
    .align(v-center);
    justify-content: space-around;
    .btn{
        width: 330rpx;
        height: 100rpx;
        background: #4385f5;
        color: #fff;
        border-radius: 50rpx;
        font-size: 32rpx;
        .align(center);
        box-shadow: 0 0 10rpx #72a3f8;
        &:last-child{
            box-shadow: 0 0 10rpx #d57174;
            background: @mainColor;
        }
    }
}


</style>